from pydantic import (
    BaseModel,
    root_validator,
    validator
)

from httpx._config import Proxy
from utils.proxy import ProxyPool


class TransportItem(BaseModel):
    http1: bool = True
    http2: bool = False
    proxy: Proxy | str  = None

    class Config:
        arbitrary_types_allowed = True

    @root_validator
    def check_passwords_match(cls, values):
        http1, http2 = values.get('http1'), values.get('http2')
        if http2:
            values['http2'] = True
            values['http1'] = False
        else:
            values['http2'] = False
            values['http1'] = True

        proxy = values.get('proxy')
        if isinstance(proxy, Proxy) or proxy is None:
            values['proxy'] = proxy
        elif isinstance(proxy, str):
            values['proxy'] = Proxy(proxy)
        else:
            values['proxy'] = None

        return values


if __name__ == '__main__':
    print(TransportItem(proxy="http://127.0.0.1:8080", http2=True))
